package com.hmall.common.config;


import com.hmall.common.interceptor.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/10/16 9:29
 * @Version: 1.0
 */
//Spring MVC 不会自动识别拦截器，必须通过配置类 “注册” 才能生效，WebConfig 就是干这个的：
@Configuration  // 标记为配置类，Spring启动时会加载
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {
    // 重写addInterceptors方法，注册拦截器
    @Override

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
}}
